#pragma once
#include <vector>
#include "Poller.h"

#if defined(__CYGWIN__)
#else
struct epoll_event;
#endif
namespace xncc {
namespace foundation {
    class Channel;
    class EpollPoller final : public Poller
    {
      public:
        EpollPoller();
        ~EpollPoller() override;

        EpollPoller(const EpollPoller&)             = delete;
        EpollPoller(const EpollPoller&&)            = delete;
        EpollPoller& operator=(const EpollPoller&)  = delete;
        EpollPoller& operator=(const EpollPoller&&) = delete;

        auto ioType() -> types::IO_MULTI_MODE::value override { return types::IO_MULTI_MODE::value::EPOLL; }
        ///< 添加一个channel  相当于把一个新的fd 注册到 epoll里了， 一个channel 关联一个fd
        void addChannel(const std::shared_ptr<Channel>& chnl) override;
        void removeChannel(const std::shared_ptr<Channel>& chnl) override;
        void updateChannel(const std::shared_ptr<Channel>& chnl) override;
        void loopOnce(int waitUs) override;

      private:
        void update(int operation, const std::shared_ptr<Channel>& chnl) const;
#if defined(__CYGWIN__)
#else
        using EventList = std::vector<struct epoll_event>;
        int       epollfd_;
        EventList events_;
#endif
    };
}  // namespace foundation
}  // namespace xncc